package org.viva.service.wx.mp;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.viva.service.sys.WebsiteService;
import org.viva.util.wx.WXBizMsgCrypt;

/**
 * 微信配置
 */
@Service
public class WxConfigServiceImpl implements WxConfigService {

    private WXBizMsgCrypt wxBizMsgCrypt;

    @Resource
    private WebsiteService websiteService;

    @Override
    public WXBizMsgCrypt getWxBizMsgCrypt() {
        if (wxBizMsgCrypt == null) {
            wxBizMsgCrypt = new WXBizMsgCrypt();
        }
        String token = websiteService.getCache().get("weixin.dyh.Token");
        String appSecret = websiteService.getCache().get("weixin.dyh.AppSecret");
        String appId = websiteService.getCache().get("weixin.dyh.AppID");
        String encodingAesKey = websiteService.getCache().get("weixin.dyh.EncodingAESKey");
        String debug = websiteService.getCache().get("weixin.dyh.debug");
        wxBizMsgCrypt.init(token, appSecret, appId, encodingAesKey);
        wxBizMsgCrypt.setDebug("true".equals(debug) ? true : false);
        return wxBizMsgCrypt;
    }

}
